package com.agan.aganjavaspyder.crawler.ct_test;

import com.agan.aganjavaspyder.crawler.ct_test.beijing.BjHrefPipeline;
import com.geccocrawler.gecco.GeccoEngine;
import com.geccocrawler.gecco.downloader.DownloadException;
import com.geccocrawler.gecco.request.HttpPostRequest;

import java.io.UnsupportedEncodingException;
import java.util.*;

/**
 * @author agan
 * @ClassName Category
 * @Description
 * @Date 2020/10/14 4:50 下午
 **/

public class BjMobileUtil {


    public static void startSpiderByHttp() throws UnsupportedEncodingException, DownloadException {

        //'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
         //       'Accept-Language': 'en',

        String url = "https://z.bj.189.cn/itemRest/commodity/list";
        HttpPostRequest req = new HttpPostRequest();

     //   req.addHeader("Accept","text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
       req.addHeader("Accept-Encoding","gzip, deflate, br");
        req.addHeader("Accept-Language","zh-CN,zh;q=0.9,en;q=0.8");
      req.addHeader("Cache-Control","no-cache, no-store, max-age=0, must-revalidate");
    //  req.addHeader("Connection","keep-alive");
        req.addHeader("Cookie","JSESSIONID=8FB79C4D0A124CA0B8C3F14027F811FD; JSESSIONID=8FB79C4D0A124CA0B8C3F14027F811FD; svid=8FB79C4D0A124CA0B8C3F14027F811FD; s_fid=3A38D3A306DCDDE1-29D62542E4EAD012; lvid=1b5cd9f92123147c082c73d33d6c2dbf; nvid=1; trkId=E86703CE-1537-4D3C-B1D3-2D935E8C01D1; 0yHmMQUi4f9KS=52q1wG31MPE1o6_yib0Ufq.zubGTIP_sPufimk0buk17G_KX0CQOaqJWmJVxooG.7fb9Qdt.qk3TDVl8MbidV.a; WT_FPC=id=120135cfaf73cf2745a1602639740969; oldtime=18550; Hm_lvt_79fae2027f43ca31186e567c6c8fe33e=1602663329; 0yHmMQUi4f9KO=5cyfRja4twdsDBkWaz94MGZKcxRdVoohCHbRvPSPXxYP0LpvWvM74Jm8tqbGrSYQjCsdjiUTNkBhyIEa9bvfMLa; 0yHmMQUi4f9KT=5UgFndY5Dzr3qqqmTxn0bpa9g.BeykVchHHTn53JBnX0CceBI0jM2cmA7KsbhyaPpzCmFP68ZuwN_WttbevBivETAvZZMITh2PNlXyEN0zaVZdbFXO8NCvcFRbKgQeY6JvGfMF9CG6AHDQ6IZtvMZy5J6KmnBewvXNG1YJiTlQvP9Vfw_YTCoq0j6j3LvRTtSDW0RPkF2X8e93TytKDtUxE.Yo0j2Lht1d850cxJp7jCTsEjS4saEfQbh8xnHPgw7oecoh5_9Yu7Dez6CN.SfCM9RDPRX6MxT4zXQ2QovUJAqunjpJu_cY3CTg0w0yTBSW; 5224c5f07e5da28b61=26eb640ae4a64f32311705753eb90f37; WT_SS=16026820649706e03b0541; jsession_id_scsva=n85CDFB649B2B4510B7DDB40FD975A859-1; s_cc=true; loginStatus=non-logined; trkHmCitycode=0; trkHmCoords=0; trkHmPageName=0; channel=wt-vivoz6; WT_si_n=MM_ADV_HOME; _gscu_1758414200=02727587s4girh16; _gscbrs_1758414200=1; cityCode=bj; SHOPID_COOKIEID=10001; trkHmClickCoords=0; s_sq=%5B%5BB%5D%5D; Hm_lvt_9004434f3a31031836fd6a07df4d1ae8=1602669689,1602669694,1602682065,1602727644; Hm_lpvt_9004434f3a31031836fd6a07df4d1ae8=1602739254; JSESSIONID=-7QqtDTj7sRbbtO9Yx7DCOZel6g48_f477dei6SrYbT4ShrBLbdj!-615896020; _gscs_1758414200=t02740118j1kklg16; 0yHmMQUi4f9KP=5Ug8Cmm5ozngqqqmTt.TcQAJIx.5Ku71FmfqAxB9UXTixgTbImTKgJZ2cdX2fzJmNn0oGZOIq8oHsfwpd7aqWEwVI9eh34IMrYNzGqtS9oXu9ZouxsbvEL8NEWnazkjxQQ0rX6p5q690mIKchay6UxlBqCBuZJT.A_l75e51uDJ9WN9PvxSfUOlnT5rCdh0n2wVNqnx01jozuPBgvli9Mj4zNE4HTwe53WHjpikfp3uMVCUKVT0WAvi3v_JrO48X1XV2h4g8Ne3Gxwiy1U6L25zLclX4LErPpn54fUwxHmYpnd1IAabyDifXOgzBSYpWKQ");
        req.addHeader("Host","z.bj.189.cn");
      req.addHeader("Pragma","no-cache");
      req.addHeader("Referer","https://z.bj.189.cn/index/category.html");
        req.addHeader("Sec-Fetch-Dest","empty");
      req.addHeader("Sec-Fetch-Mode","cors");
      req.addHeader("Sec-Fetch-Site","same-origin");
      req.addHeader("X-Requested-With","XMLHttpRequest");
        req.addHeader("User-Agent","Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.75 Mobile Safari/537.36");
        req.addHeader("Content-Type","application/x-www-form-urlencoded;charset=UTF-8");
        req.addHeader("Referer","https://z.bj.189.cn/index/category.html");
        //req.setUrl("https://z.bj.189.cn/itemRest/commodity/list");
        Map<String, String> params = new HashMap<>();
        params.put("PSAvnQfG","5Kq65HdCIb7bSp7LLBDiUgh0xrpUuD5z2_.hGwBuXPGOktEgqONgZWQTVo5rU_N1MG979aFSp7V7APECGJiMwmQFPsu4_oW2cPL1mkcFFpAkppE2gFjt8sEkBTns.3w4A5mrlcSef2GxvhZrKr78H32cJhYVHy1BGSDi4tJfynSGTMlrNq6dyFwGbdHa_gDIlfH265wpIhrc0HVak29Qum6XpeLXurZNcJgZUCbmx6lb79TgYfXeL8QxRw3ng1TwO18_L_Hh7Q__Dxjc4hDTodNZNluxR8jjm8d9pfMrqwpJz8QX_2dlCQGFCr_Z.ilzMBQJGKMgHC2pRJ1keokX0CioDmPJYjhHarCIVUYi66ig");
        req.setUrl(new BjHrefPipeline().setRequestParam(url, params));
        Map<String, String> fields = new HashMap<>();

        //fields.put("busInfo","%7B%22shopId%22:%222620170428857852117203030016%22,%22sequenceNo%22:%225%22,%22page%22:%7B%7D,%22channelRel%22:%225%22,%22epps%22:%5B%5D,%22searchKey%22:%22%E7%89%B9%E6%83%A0%E8%B4%AD%E6%9C%BA%22%7D");
        //fields.put("busInfoPara","%7B%22shopId%22:%222620170428857852117203030016%22,%22sequenceNo%22:%225%22,%22page%22:%7B%7D,%22channelRel%22:%225%22,%22epps%22:%5B%5D,%22searchKey%22:%22%E7%89%B9%E6%83%A0%E8%B4%AD%E6%9C%BA%22%7D");
        fields.put("busInfo", "{\"shopId\":\"2620170428857852117203030016\",\"sequenceNo\":\"5\",\"page\":{},\"channelRel\":\"5\",\"epps\":[],\"searchKey\":\"特惠购机\"}");
        fields.put("busInfoPara","{\"shopId\":\"2620170428857852117203030016\",\"sequenceNo\":\"5\",\"page\":{},\"channelRel\":\"5\",\"epps\":[],\"searchKey\":\"特惠购机\"}");
        fields.put("appKey","C2F9BEBCE8DD3CEDFF8016A4B8248FF5");
        fields.put("sign","C15F529FEE267A8ED31696F8DDE50321");
        //fields.put("timeStamp", DateUtil.format(new Date(),PURE_DATETIME_PATTERN));
        fields.put("timeStamp","20201015013529");
        req.setFields(fields);
        req.addParameter("PSAvnQfG","125fJ5kj0RJ7wkcvl6dl.nohqE.KoHAZiKhwZXqFjNN8qZY3k5ABpjQoXkMdstVobrcu1HBvMcurMfWWM9gJ3TdKkpZNC5X_RV0koWgpwEwSEMm.YVFSP8qD5WoP.PMRTM_vbpp0wb8isuJFfq9W4JJv1hFSmF8OBGgiBubKr9fEyDMhgoG2RkyVbaGGdip9NoHQyBPoizkRsrnLpwITIWQ9mFoXi9SepWzWJTeed7A7usOpguCzrmhpBEPc4XlaHYjqmCAhQ86ULuT9ntmVhYmvXLazarK2TMGL.6530MFm6Rt4a8vaC.GN9Gx9ohhI1Fp_VzFZKP3raJs_zUFmJnY.bf_.oNZr19jhOSP8chg.e7");

        System.out.println(req.getFields()+"----"+req.getHeaders()+"---"+req.getParameters()+"---"+req.getCharset()+"----"+req.getCookies());
/*      DynamicGecco.json()
                .gecco(new String[]{new BjHrefPipeline().setRequestParam(url, params)},"consolePipeline","BjHrefPipeline")
                .register();*/
        GeccoEngine.create("com.agan.aganjavaspyder.crawler")
                .interval(5000)
                .loop(false)
                .seed(req)
                .engineStart();

    }

    public static void main(String[] args) throws UnsupportedEncodingException, DownloadException {

        startSpiderByHttp();

    }

}
